package main.java.com.mengxj.listmap;

import com.alibaba.fastjson.JSON;

import java.util.*;

/**
 * 1，集合框架简单说明
 * 2，new 出来的集合 和 Arrays.as 出来的集合区别
 *      前者可以任意修改，后者只能查看
 *
 * 1，集合有一个顶级接口：Collection，有两个重要的子类接口：List，Set
 * List：数据可以重复，数据顺序（按照插入顺序排列）
 *      ArrayList
 *      LinkedList
 * Set：数据不可以重复，数据顺序（按照hash值排序）
 *      HashSet
 *
 * 想要获取到(以下数组元素2个就行)
 * {
 *     "name": "张三",
 *     "hobby": ["", ""],
 *     "school": {
 *         "name": "",
 *         "address": "",
 *         "teachers": [
 *              {
 *                  "name": ""
 *                  "address": ""
 *              }
 *         ]
 *     }
 * }
 * @author mengxj
 */
public class ListMapDemo {

    public static void main(String[] args) {
        Map<String, Object> res = new HashMap<>();
        res.put("name", "张三");
        res.put("hobby", Arrays.asList("篮球", "跑步"));
        Map<String, Object> school = new HashMap<>();
        res.put("school", school);
        school.put("name", "xxx一中");
        school.put("address", "吉林长春");
        Map<String, String> teacher1 = new HashMap<>();
        Map<String, String> teacher2 = new HashMap<>();
        List<Map<String, String>> teachers = Arrays.asList(teacher1, teacher2);
        school.put("teachers", teachers);
        teacher1.put("name", "老师1");
        teacher1.put("address", "长春南关");
        teacher2.put("name", "老师2");
        teacher2.put("address", "长春朝阳");
        String resLine = JSON.toJSONString(res);
        System.out.println(resLine);
    }

    static void demo2(){
        Map<String, Object> res = new HashMap<>();
        res.put("name", "张三");
        res.put("hobby", Arrays.asList("篮球", "跑步"));
        Map<String, Object> school = new HashMap<>();
        school.put("name", "xxx一中");
        school.put("address", "吉林长春");
        Map<String, String> teacher1 = new HashMap<>();
        teacher1.put("name", "老师1");
        teacher1.put("address", "长春南关");
        Map<String, String> teacher2 = new HashMap<>();
        teacher2.put("name", "老师2");
        teacher2.put("address", "长春朝阳");
        List<Map<String, String>> teachers = Arrays.asList(teacher1, teacher2);
        school.put("teachers", teachers);
        res.put("school", school);
        String resLine = JSON.toJSONString(res);
        System.out.println(resLine);
    }

    static void demo1(){
        List<String> list1 = new ArrayList<>();
        list1.add("q1");
        list1.add("q2");
        List<String> list2 = Arrays.asList("q1", "a2");
        list1.add("q3");
        List<String> list3 = new ArrayList<>(list2);
        list3.add("as");
    }
}
